package com.qfedu.yige.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qfedu.yige.common.Result;
import com.qfedu.yige.pojo.BatterySwappingCabinet;
import com.qfedu.yige.service.BatterySwappingCabinetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/BSC")
public class BatterySwappingCabinetController {

    @Autowired
    private BatterySwappingCabinetService batterySwappingCabinetService;

    //增加
    @PostMapping("/add")
    public Result add( BatterySwappingCabinet batterySwappingCabinet) {
        if(batterySwappingCabinetService.save(batterySwappingCabinet)){
            return Result.success("");
        }
        return Result.fail("添加失败！");
    }
    //删除
    @GetMapping("/delete")
    public Result delete(@RequestBody String BSDId) {
        if(batterySwappingCabinetService.removeById(BSDId)){
            return Result.success("");
        }
        return Result.fail("删除失败！");
    }
    //修改
    @PostMapping("/update")
    public Result update(@RequestBody BatterySwappingCabinet batterySwappingCabinet) {


        Boolean f = batterySwappingCabinetService.updateById(batterySwappingCabinet);
        if(f){
            return Result.success("");
        }
        return Result.fail("修改失败！");
    }

    //获取附近换电柜
    @GetMapping("/nearby")
    public Result nearby(@RequestParam("x" ) double x, @RequestParam("y" ) double y) {

        List<BatterySwappingCabinet> list = batterySwappingCabinetService.Nearby(x,y);
        if(!list.isEmpty()){

            return Result.success(list);
        }
        return Result.fail("获取附近换电柜失败！");
    }
    //根据id查BSC
    @GetMapping("/findById")
    public Result findById(String BSCId) {

        BatterySwappingCabinet batterySwappingCabinet = batterySwappingCabinetService.getById(BSCId);
        if(batterySwappingCabinet != null){
            return Result.success(batterySwappingCabinet);
        }
        return Result.fail("根据id获取换电柜失败！");
    }

    //预约
    @GetMapping("/subscribe")
    public Result subscribe(int BSCId,int userid) {

        Result result =  batterySwappingCabinetService.subscribe(BSCId,userid);
        return result;
    }
    //取消预约
    @GetMapping("/cancelSubscribe")
    public Result cancelSubscribe(int BSCId,int userid) {

        Result result =  batterySwappingCabinetService.cancelSubscribe(BSCId,userid);
        return result;
    }
    //收藏充电柜
    @GetMapping("/collect")
    public Result collect(int BSCId,int userid) {

        Result result =  batterySwappingCabinetService.collect(BSCId,userid);
        return result;
    }
    //取消收藏
    @GetMapping("/cancelCollect")
    public Result cancelCollect(int BSCId,int userid) {

        Result result =  batterySwappingCabinetService.cancelCollect(BSCId,userid);
        return result;
    }
    //获取收藏列表
    @GetMapping("/collectList")
    public Result collectList(int userid) {

        Result result =  batterySwappingCabinetService.collectList(userid);
        return result;
    }


}
